package hu.berczi.Util.File;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;

public class FileUtil {

	static public ArrayList<String> getContents(File aFile, String charSetName) {
		ArrayList<String> lines = new ArrayList<String>();
		try {

			BufferedReader input = new BufferedReader(new InputStreamReader(
					new FileInputStream(aFile), Charset.forName(charSetName)));

			try {
				String line = null;
				while ((line = input.readLine()) != null) {
					lines.add(line);
				}
			} finally {
				input.close();
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}

		return lines;
	}

	static public void setContents(File aFile, String content) {
		try {
			FileWriter fstream = new FileWriter(aFile);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(content);
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error writing file: " + e.getMessage());
		}

	}

}
